let httpUrl = 'https://weipiaopiao.top:10070';

async function getAImage() {
    let body = document.querySelector('body');
    let imgArr = await axios.get(`${httpUrl}/getbg`);
    imgArr = imgArr.data;

    let index = Math.floor(Math.random() * imgArr.length);
    imgArr[index] = httpUrl + imgArr[index];
    body.style.backgroundImage = `url(${imgArr[index]})`;

}


window.onload = function() {
    getAImage();
    getcurrentTime();


}



let searchEngineIndex = 0; //默认百度
let engineList = [{ name: 'baidu', imgurl: '../img/baidu.ico', href: 'https://www.baidu.com/s?wd=' },
    { name: 'bilibili', imgurl: '../img/bilibili.png', href: 'https://search.bilibili.com/all?keyword=' },
    { name: 'google', imgurl: '../img/google.jpg', href: 'https://www.google.com/search?q=' }
]

//搜索引擎转换
function changeSearchEngine() {
    let brandIcon = document.querySelector('.brandIcon');
    let brandIcon_Img = document.querySelector('.brandIcon img');

    brandIcon.onclick = function() {

        // let temparr = brandIcon_Img.src.split('/');
        // let currentSrc = '/' + temparr[temparr.length - 1];
        searchEngineIndex++;
        if (searchEngineIndex > engineList.length - 1) {
            // 索引大于引擎数置回百度
            searchEngineIndex = 0;
        }
        brandIcon_Img.src = engineList[searchEngineIndex].imgurl;

    }

    inputBox.onkeydown = function(e) {
        if (e.keyCode == 9) {
            e.preventDefault()
                //  tob切换搜索引擎
            brandIcon.click();
        };
    }


}

changeSearchEngine()


//搜索点击
searchBtn.onclick = function(e) {
    e.preventDefault();
    let value = inputBox.value;
    if (!value) return;

    window.location.href = engineList[searchEngineIndex].href + value;
    inputBox.value = '';



}

inputBox.onkeyup = function(e) {
    if (e.keyCode == 13) {
        //回车执行查询
        searchBtn.click();
    };

}



ulContainerP.onclick = function() {
    if (videoUl.style.display === 'none') {
        videoUl.style.display = 'block';
    } else {
        videoUl.style.display = 'none'
    }


}


//获取时间
function getcurrentTime() {
    let myDate = new Date();
    let mytime = myDate.toLocaleTimeString();
    mytime = mytime.slice(2);
    time.innerHTML = mytime;
}
setInterval(() => {
    getcurrentTime();
}, 1000);